import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import './plugins/element.js'

Vue.config.productionTip = false

router.beforeEach((to, from, next) => {
  if (to.path == '/') {
    next()
  } else {
    const userToken = store.state.access_token;
    if (!userToken) {
      store.commit("setAccesstoken", localStorage.getItem('token'));
    }
    if (!userToken && !localStorage.getItem('token')) {
      next({ path: '/' })
    } else {
      next()
    }
  }
})
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
